﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms.VisualStyles;
using SolidWorks.Interop.sldworks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;

namespace SolidworksDLL
{
    public static class BodyHelp
    {
        public static List<Body2> GetAllBody(PartDoc partDoc)
        {
            List<Body2> bodies = new List<Body2>();

            object[] objs = (object[])partDoc.GetBodies2(-1, false);
            if (objs != null)
            {
                foreach (Body2 item in objs)
                {
                    bodies.Add(item);
                }
            }

            return bodies;
        }

        public static List<Body2> GetAllBody(Component2 compDoc)
        {
            List<Body2> bodies = new List<Body2>();

            object[] objs = (object[])compDoc.GetBodies2(-1);
            if (objs != null)
            {
                foreach (Body2 item in objs)
                {
                    bodies.Add(item);
                }
            }

            return bodies;
        }

        public static void GetFaces(object[] objs, ref List<Face2> faces)
        {
            if (objs != null)
            {
                foreach (Face2 item in objs)
                {
                    faces.Add(item);
                }
            }
        }

        public static List<Face2> GetAllFaces(Body2 body)
        {
            List<Face2> faces = new List<Face2>();
            object[] objs = (object[])body.GetFaces();
            GetFaces(objs, ref faces);
            return faces;
        }

        public static List<Face2> GetAllFaces(Feature feature)
        {
            List<Face2> faces = new List<Face2>();
            object[] objs = (object[])feature.GetFaces();
            GetFaces(objs, ref faces);
            return faces;
        }

        public static void GetLoops(object[] objs, ref List<Loop2> loops)
        {
            if (objs != null)
            {
                foreach (Loop2 item in objs)
                {
                    loops.Add(item);
                }
            }
        }

        public static List<Loop2> GetAllLoops(Face2 face)
        {
            List<Loop2> loops = new List<Loop2>();
            object[] objs = (object[])face.GetLoops();
            GetLoops(objs, ref loops);
            return loops;
        }

        public static List<Loop2> GetAllLoops(CoEdge coEdge)
        {
            List<Loop2> loops = new List<Loop2>();
            object[] objs = (object[])coEdge.GetLoop();
            GetLoops(objs, ref loops);
            return loops;
        }

        public static void GetEdges(object[] objs, ref List<Edge> edges)
        {
            if (objs != null)
            {
                foreach (Edge item in objs)
                {
                    edges.Add(item);
                }
            }
        }

        public static List<Edge> GetAllEdges(Body2 body)
        {
            List<Edge> edges = new List<Edge>();
            object[] objs = (object[])body.GetEdges();
            GetEdges(objs, ref edges);
            return edges;
        }

        public static List<Edge> GetAllEdges(Face2 face)
        {
            List<Edge> edges = new List<Edge>();
            object[] objs = (object[])face.GetEdges();
            GetEdges(objs, ref edges);
            return edges;
        }

        public static List<Edge> GetAllEdges(CoEdge coEdge)
        {
            List<Edge> edges = new List<Edge>();
            object[] objs = (object[])coEdge.GetEdge();
            GetEdges(objs, ref edges);
            return edges;
        }

        public static List<Edge> GetAllEdges(Loop2 loop)
        {
            List<Edge> edges = new List<Edge>();
            object[] objs = (object[])loop.GetEdges();
            GetEdges(objs, ref edges);
            return edges;
        }

        public static void GetVertexs(object[] objs, ref List<Vertex> Vertexs)
        {
            if (objs != null)
            {
                foreach (Vertex item in objs)
                {
                    Vertexs.Add(item);
                }
            }
        }

        public static List<Vertex> GetAllVertexs(Body2 body)
        {
            List<Vertex> Vertexs = new List<Vertex>();
            object[] objs = (object[])body.GetVertices();
            GetVertexs(objs, ref Vertexs);
            return Vertexs;
        }

        public static List<Vertex> GetAllVertexs(Edge edge)
        {
            List<Vertex> Vertexs = new List<Vertex>();
            Vertex vertex1 = edge.GetStartVertex();
            Vertexs.Add(vertex1);
            Vertex vertex2 = edge.GetEndVertex();
            Vertexs.Add(vertex2);
            return Vertexs;
        }

        public static List<Vertex> GetAllVertexs(Loop2 loop)
        {
            List<Vertex> Vertexs = new List<Vertex>();
            object[] objs = (object[])loop.GetVertices();
            GetVertexs(objs, ref Vertexs);
            return Vertexs;
        }
    }
}